﻿@model TaskModel
@{
    ViewBag.Title = "任务管理";
    Layout = "_Default";
}
@section css {
    <link href="~/lib/longbow-select/longbow-select.css" rel="stylesheet" />
    <link href="~/css/tasks.css" rel="stylesheet" asp-append-version="true" />
}
@section javascript {
    <script src="~/lib/longbow-select/longbow-select.js"></script>
    <script src="~/js/tasks.js" asp-append-version="true"></script>
}
@section tableButtons {
    <button class='info btn btn-sm btn-info' asp-auth="info"><i class='fa fa-info'></i><span>日志</span></button>
}
@section cardbody {
    <div class="alert alert-danger" role="alert" asp-condition="@Model.IsDemo">
        <span>演示系统禁止修改定时后台任务</span>
    </div>
}
@section query {
    <div class="alert alert-info">
        <p class="font-weight-bold">后台任务说明：</p>
        <p>1. 默认任务 (立即执行，仅执行一次)</p>
        <p>
            <code>
                TaskServicesManager.GetOrAdd("简单任务", token => Task.Delay(1000));
            </code>
        </p>
        <p>2. 周期性任务 (1 分钟后间隔 5 秒执行 2 次任务)</p>
        <p>
            <code>
                var trigger = TriggerBuilder.Default.WithInterval(TimeSpan.FromSeconds(5)).WithRepeatCount(2).WithStartTime(DateTimeOffset.Now.AddMinutes(1)).Build();
                <br />
                TaskServicesManager.GetOrAdd("测试任务", token => Task.Delay(1000), trigger);
            </code>
        </p>
        <p>3. Cron 表达式任务 (间隔 5 秒循环执行任务)</p>
        <p>
            <code>
                TaskServicesManager.GetOrAdd("Cron 表达式任务", token => Task.Delay(1000), TriggerBuilder.Build("*/5 * * * * *"));
            </code>
        </p>
    </div>
}
@section modal {
    <div class="modal-header">
        <h5 class="modal-title" id="myModalLabel">任务编辑窗口</h5>
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    </div>
    <div class="modal-body">
        <form class="form-inline">
            <div class="row">
                <input type="hidden" id="taskID" />
                <div class="form-group col-12">
                    <label class="control-label" for="taskName">任务名称</label>
                    <input type="text" class="form-control flex-sm-fill" id="taskName" placeholder="不可为空，50字以内" maxlength="50" data-valid="true" />
                </div>
                <div class="form-group col-12">
                    <label class="control-label" for="taskCron">Cron表达式</label>
                    <input type="text" class="form-control flex-sm-fill" id="taskCron" placeholder="不可为空，2000字以内" maxlength="2000" data-valid="true" />
                </div>
                <div class="form-group col-12">
                    <label class="control-label" for="taskContent">内置任务</label>
                    <select id="taskList" data-toggle="lgbSelect">
                        @foreach (var name in Model.Tasks)
                        {
                            <option value="@name">@name</option>
                        }
                    </select>
                </div>
            </div>
        </form>
    </div>
}
@section customModal {
    <div class="modal fade" id="dialogLog" tabindex="-1" role="dialog" data-backdrop="static" aria-labelledby="taskModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="taskModalLabel">任务日志窗口</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                </div>
                <div class="modal-body" style="background-color: #174482; color: #fff;">
                    <div id="taskMsg" class="form-group" style="height: 500px; overflow: auto;">
                        <div></div>
                    </div>
                </div>
                <div class="modal-footer">
                    <a class="btn"><i class="fa fa-check-square-o" style="width: 13px;"></i><span>自动滚屏</span></a>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">
                        <i class="fa fa-times"></i>
                        <span>关闭</span>
                    </button>
                </div>
            </div>
        </div>
    </div>
}